<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <style>
        .hd-form-upload {
            width: 80px;
            height: 80px;
            display: inline-block;
            cursor: pointer;
        }

        .hd-form-upload input {
            display: none;
        }

        .hd-form-upload span {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            float: left;
            overflow: hidden;
            background-color: #ddd;
        }

        .hd-form-upload span img {
            width: 100%;
            display: inline;
            vertical-align: middle;
        }

        .hd-form-upload span i {
            width: 80px;
            height: 80px;
            float: left;
            position: relative;
        }

        .hd-form-upload  span i:before {
            content: "";
            border-top: 2px solid #bbb;
            position: absolute;
            top: 39px;
            left: 20px;
            right: 20px;
        }

        .hd-form-upload  span i:after {
            content: "";
            border-right: 2px solid #bbb;
            position: absolute;
            top: 20px;
            left: 39px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">名称(CN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请输入名称(CN)" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称(EN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_name" lay-verify="required" placeholder="请输入名称(EN)" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类图标</label>
                <div class="layui-input-block">
                    <a class="pear-btn" onclick="show()">选择</a>
                    <a class="pear-btn" id="icon">上传</a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload">
                        <span id="thumb-icon-thumb">
                            <i></i>
                        </span>
                    </label>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Pc图标</label>
                <div class="layui-input-block">
                    <a class="pear-btn" onclick="show(2)">选择</a>
                    <a class="pear-btn" id="icon2">上传</a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">未选中</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload">
                        <span id="thumb-icon-thumb1">
                            <i></i>
                        </span>
                    </label>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Pc图标</label>
                <div class="layui-input-block">
                    <a class="pear-btn" onclick="show(3)">选择</a>
                    <a class="pear-btn" id="icon3">上传</a>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">选中</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload">
                        <span id="thumb-icon-thumb3">
                            <i></i>
                        </span>
                    </label>
                </div>
            </div>
            <input type="hidden" name="icon" id="icon_thumb">
            <input type="hidden" name="icon_pc" id="icon_thumb1">
            <input type="hidden" name="icon_pc_on" id="icon_thumb3">
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script src="/static/common/jquery-3.6.0.min.js"></script>
<script>
    function show(type=1) {
        layer.open({
            type: 2,
            title: '选择icon',
            shade: 0.1,
            area: ['800px', '500px'],
            content: '/Category/showIcon?type='+type
        });
    }
    layui.use(['form', 'jquery', 'upload', 'element'], function() {
        let form = layui.form;
        let upload = layui.upload;
        let $ = layui.jquery;

        upload.render({
            elem: '#icon'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res){
                if(res.code == 200){
                    $("#thumb-icon-thumb").html('<img src="'+ res.data + '" />');
                    $("#icon_thumb").val(res.data);
                } else {
                    layer.msg(res.msg);
                }
            }
        });
        upload.render({
            elem: '#icon2'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res){
                if(res.code == 200){
                    $("#thumb-icon-thumb1").html('<img src="'+ res.data + '" />');
                    $("#icon_thumb1").val(res.data);
                } else {
                    layer.msg(res.msg);
                }
            }
        });

        upload.render({
            elem: '#icon3'
            ,url: "{:url('Pub/blob')}"
            ,accept:'images'
            ,acceptMime: 'image/*'
            ,exts:'jpeg|jpg|png'
            ,done: function(res){
                if(res.code == 200){
                    $("#thumb-icon-thumb3").html('<img src="'+ res.data + '" />');
                    $("#icon_thumb3").val(res.data);
                } else {
                    layer.msg(res.msg);
                }
            }
        });

        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            $.ajax({
                url: '/Category/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>